package legumes.shared.domain;

import java.io.Serializable;

public class Cost implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private float value;
	private boolean exact;

	public Cost(float value, boolean exact) {
		super();
		this.value = value;
		this.exact = exact;
	}

	@Override
	public String toString() {
		if (isExact()) {
			return String.valueOf(getValue());
		} else {
			return "~" + String.valueOf(getValue());
		}
	}

	public Cost(float value) {
		this(value, true);
	}

	public Cost() {
		this(0, true);
	}

	public Cost(Cost c_) {
		this(c_.getValue(), c_.isExact());
	}

	public Cost plus(Cost c_) {
		setValue(getValue() + c_.getValue());
		setExact(isExact() && c_.isExact());
		return this;
	}

	/**
	 * @return the value
	 */
	public float getValue() {
		return value;
	}

	/**
	 * @param value
	 *            the value to set
	 */
	public void setValue(float value) {
		this.value = value;
	}

	/**
	 * @return the exact
	 */
	public boolean isExact() {
		return exact;
	}

	/**
	 * @param exact
	 *            the exact to set
	 */
	public void setExact(boolean exact) {
		this.exact = exact;
	}

	public Cost minus(Cost c_) {
		setValue(getValue() - c_.getValue());
		setExact(isExact() && c_.isExact());
		return this;
	}

	public Cost plus(float v_) {
		setValue(getValue() + v_);
		return this;
	}

	public void div(int n_) {
		setValue(getValue() / n_);
	}

}
